<template>
  <div class="image-water-fall">
    <waterfall
      :col="col"
      :data="data"
    >
      <div
        v-for="(item, index) in data"
        :key="index"
        class="cell-item"
      >
        <img
          :src="item.fileUrl"
          alt="无法加载"
        >
        <div class="item-body">
          <div class="item-footer">
            <div class="item-title">
              {{ item.title }}
            </div>
            <div class="item-view">
              <el-button
                type="text"
                icon="el-icon-zoom-in"
                @click="viewImage(item.ossId)"
              />
            </div>
            <div class="item-del">
              <el-button
                type="text"
                icon="el-icon-delete"
                @click="deleteImage(item.ossId)"
              />
            </div>
          </div>
        </div>
      </div>
    </waterfall>
  </div>
</template>

<script>
  export default {
    props: {
      data: {
        type: Array,
        default: () => []
      },
      col: {
        type: Number,
        default: 4
      }
    },
    methods: {
      deleteImage(ossId) {
        this.$confirm('确定删除该图片吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$emit('delete-image', ossId);
          console.log(ossId)
        })
          .catch(() => { });
      },
      viewImage(ossId) {
        this.$emit('view-image', ossId);
        console.log(ossId)
      }
    }
  };
</script>

<style scoped>
  .cell-item {
    height: 220px;
    margin: 0px 6px 6px 0px;
    background: #ffffff;
    border: 2px solid #f0f0f0;
    border-radius: 6px;
    overflow: hidden;
    box-sizing: border-box;

    img {
      width: 100%;
      height: 100%;
      max-height: 170px;
      display: flex;
    }

    .item-body {
      padding: 5px;
      padding-right: 0;
      margin: 0;
      width: 100%;

      .item-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .item-title {
          width: 40%;
          font-size: 14px;
          color: rgba(0, 0, 0, 0.8);
        }

        .item-view {
          display: flex;
          margin-left: 34%;
          align-items: center;
          justify-content: center;
          color: rgba(0, 0, 0, 0.6);
        }
        .item-del {
          display: flex;
          margin-right: 1%;
          align-items: center;
          justify-content: center;
          color: rgba(0, 0, 0, 0.6);
          &:deep(.el-button){
            /* background-color: red; */
          }
        }
      }
    }
  }
</style>